<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<jsp:include page="/common/commonCss.jsp" />
<jsp:include page="/common/commonJs.jsp" />
<script language="javascript" src="${basePath }commonJs/quinn_commons.js"></script>
<script type="text/javascript" src="${basePath}commonJs/tags/My97DatePicker/WdatePicker.js"></script>
<title>嘉童游乐中心-库存调整</title>
<script type="text/javascript">
	$(document).ready(function (){
		$("#branIdSelect option[value='${branId}']").attr("selected",true);
		refreshSelect();
		$("#fkBranId").val("${branId}");
		initTable();
	});

	function initTable()
	{
		$("#pkStgadjId").val($.trim($("#stgadjIdVal").val()));
		$("#startSearchTime").val($.trim($("#startVal").val()));
		$("#endSearchTime").val($.trim($("#endVal").val()));
		var form = $("#stockCorrectForm");
		var pagenbean = new PageBean(form);
		pagenbean.setTableId("stockCorrectTable");
		pagenbean.setCallback(callBack);
		pagenbean.setFootId("stockCorrectFoot");
		setPagebeanObj(pagenbean);
		pagenbean.doPage();
	}
	
	function callBack(data)
	{
		if(data == null)
			{
				return;
			}
		$.each(data,function(ind, obj) {//显示采购订单
			obj = emptyJson(obj);
   			var obj2 = emptyJson(obj.workflowVo);
			var i = ind + 1;
			var pkStgadjId = obj.pkStgadjId;
			var htm = "<tr>";
			htm += "<td>" + i + "</td>";
			htm += "<td class='lv'><a href='#'onclick = 'toStockCorrectDetail(this);' statusDesc='"+obj2.statusDesc+"' pkStgadjId = '"+pkStgadjId+"'>" + pkStgadjId + "</a></td>";
			htm += "<td>" + obj.usrName + "</td>";
			htm += "<td>" + getSmpFormatDate(new Date(obj.applyTime), false)  + "</td>";
			htm += "<td>" + obj2.statusDesc + "</td>";
            htm += "<td>" + obj2.result + "</td>";
            if(obj.status == '1')
            	htm += "<td class='lv'><input type='button' pkStgadjId='"+pkStgadjId+"' class=\"btn_l\" value='编辑' onclick=\"editCorrect(this)\"/>&nbsp;&nbsp;&nbsp;<input type='button' pkStgadjId='"+pkStgadjId+"' class='btn_l' value='删除' onclick=\"delCorrect(this)\"/></td>";
            else{
            	if(obj.status == '2'){
							if(obj2.isCurrtOpt == '1')//当前用户
								{
									if(obj2.isStartUser == "1")//申请用户
									{
										htm += "<td class=\"lv\"><input type='button' statusDesc='"+obj2.statusDesc+"' pkStgadjId='"+pkStgadjId+"' class=\"btn_l\" value='重新申请' onclick=\"completeCorrect2(this)\"/></td>";
									}
								else//处理用户
									{
										htm += "<td class=\"lv\"><input type='button' statusDesc='"+obj2.statusDesc+"' pkStgadjId='"+pkStgadjId+"' class=\"btn_l\" value='处理' onclick=\"completeCorrect(this)\"/></td>";
									}
								}
							else
								{
									htm += "<td></td>";
								}
								
            	}else{
            		htm += "<td></td>";
            	}
            } 
            htm += "</tr>";
			$("#stockCorrectTable").find("tr:eq(" + ind + ")").after(htm);
		});
	}
	
	//删除
	function delCorrect(obj)
	{
		$.messager.confirm('警告', $common_confirm_delete, function(r) {
			if (r) {
				var pkStgadjId = $(obj).attr("pkStgadjId");
				$.ajax({
					url:"${basePath}StockCorrect/delScmStgadjPrds.shtml",
					data:{"pkStgadjId":pkStgadjId},
					dataType:"text",
					type:"post",
					async:false,
					success:function (result)
					{
						if(result == 1)
						{
							alertInfo($common_delete_success);
							initTable();
						}
						if(result == 0)
						{
							alertError($common_delete_failure);
						}
					},
					error : function(XMLHttpRequest) {
						ajaxError(XMLHttpRequest);
					}
				});	
			}
		});
	}
	
	//编辑
	function editCorrect(obj)
	{
		var pkStgadjId = $(obj).attr("pkStgadjId");
		$("#toPkStgadjId").val(pkStgadjId);
		$("#toStockaddCorrectX")[0].submit();
	}
	
	//申请单用户处理退回的申请
	function completeCorrect2(obj)
	{
		var pkStgadjId = $(obj).attr("pkStgadjId");
		$("#toPkStgadjId").val(pkStgadjId);
		$("#toStockaddCorrectX")[0].submit();
	}
	
	//处理
	function completeCorrect(obj)
	{
		var pkStgadjId = $(obj).attr("pkStgadjId");
		var statusDesc = $(obj).attr("statusDesc");
		$("#ShenStgadjId").val(pkStgadjId);
		$("#statusDesc").val(statusDesc);
		$("#url").val("stock/stock_shenheCorrect");
		$("#toStockShenheCorrect")[0].submit();
		
	}
	
	//跳转到流程查看页面
	function toStockCorrectDetail(obj)
	{
		var pkStgadjId = $(obj).attr("pkStgadjId");
		var statusDesc = $(obj).attr("statusDesc");
		$("#ShenStgadjId").val(pkStgadjId);
		$("#statusDesc").val(statusDesc);
		$("#url").val("stock/stock_detailCorrect_x");
		$("#toStockShenheCorrect")[0].submit();
	}
	
	//更换门店
	function branSelectFun() {
		$("#fkBranId").val($("#branIdSelect").val());
	}
</script>
</head>
<body class="bg">
	<div class="content m_auto">
		<div class="content_l mt10">
			<ul>
			<shiro:hasPermission name="StockGoodsIn/toStock_goodsIn.shtml">
				<li><a href="${basePath}StockGoodsIn/toStock_goodsIn.shtml"><i class="nav_icon_b"></i><br>商品入库</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockQuery/toStockQuery.shtml">
				<li><a href="${basePath}StockQuery/toStockQuery.shtml"><i class="nav_icon_b"></i><br>库存查询</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockGoodsOut/toStockGoodsOut.shtml">
				<li><a href="${basePath}StockGoodsOut/toStockGoodsOut.shtml"><i class="nav_icon_b"></i><br>商品出库</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockTaking/toStockTaking.shtml">
				<li><a href="${basePath}StockTaking/toStockTaking.shtml"><i class="nav_icon_a"></i><br>库存盘点</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="StockCorrect/toStockCorrect.shtml">
				<li class="content_hover"><a href="${basePath}StockCorrect/toStockCorrect.shtml"><i class="nav_icon_f"></i><br>库存调整</a></li>
			</shiro:hasPermission>
			</ul>
		</div>
		<div class="content_r mt10">
			<div class="p20">
				<div class="file_single_dl f14 fixed">
					<dl class="fixed" style="overflow: hidden">
						<dd>
							<label>库存调整申请编号：</label><input type="text" class="iput_t w200" id="stgadjIdVal">
						</dd>
						<dd>
							<label>申请时间：</label>
							<input type="text" id="startVal" class="Wdate iput_t w82"
								onClick="WdatePicker({dateFmt:'yyyy/MM/dd',isShowWeek:true,isShowClear:true,readOnly:true})">
							<span>至</span>
							<input type="text" id="endVal" class="Wdate iput_t w82"
								onClick="WdatePicker({dateFmt:'yyyy/MM/dd',isShowWeek:true,isShowClear:true,readOnly:true})">
						</dd>
						<dd><label>所属门店：</label>
	                		<!----select--->
	                  	 	<div class="uboxstyle">
	                        	<select name="branIdSelect" id="branIdSelect" onchange="branSelectFun();">
	                        		<c:forEach items="${branList}" var="bran">
	                        			<option value="${bran.pkBranId}">${bran.branName}</option>
	                        		</c:forEach>
	                        	</select>
	                   		 </div>
	                   		 <!----select--->
                 		</dd>
						<dd class="fr">
							<input type="button" class="btn ml10 fr" value="查询" onclick="initTable();"> 
							<shiro:hasPermission name="stock:add5">
							<input class="btn ml10 fr" type="button" value="创建库存调整"
								onclick="javascript:window.location.href='${basePath}StockCorrect/toStockAddCorrect.shtml'">
							</shiro:hasPermission>
						</dd>
					</dl>
				</div>

				<table class="table" id="stockCorrectTable">
					<tr>
						<th>序号</th>
						<th>库存调整申请编号</th>
						<th>申请人</th>
						<th>申请时间</th>
						<th>审批状态</th>
						<th>审批结果</th>
						<th>操作</th>
					</tr>
				</table>
				<!----翻页----->
				<div class="page fr m10" id="stockCorrectFoot"></div>
				<!----翻页----->
			</div>
		</div>
	</div>
	<!-- 表单 -->
	<form action="${basePath}StockCorrect/findScmStgAdj.shtml" id="stockCorrectForm" method="post">
		<input type="hidden" name="pageSize" value="10"> 
		<input type="hidden" name="pageNo" value="1"> 
		<input type="hidden" name="startSearchTime" id="startSearchTime">
		<input type="hidden" name="endSearchTime" id="endSearchTime">
		<input type="hidden" name="pkStgadjId" id="pkStgadjId">
		<input type="hidden" name="fkBranId" id="fkBranId">
	</form>
	
	<form action="${basePath}StockCorrect/toStockaddCorrectX.shtml" id="toStockaddCorrectX" method="post">
		<input type="hidden" name="pkStgadjId" id="toPkStgadjId">
	</form>
	
	<form action="${basePath}StockCorrect/toStockShenheCorrect.shtml" id="toStockShenheCorrect" method="post">
		<input type="hidden" name="pkStgadjId" id="ShenStgadjId">
		<input type="hidden" name="statusDesc" id="statusDesc">
		<input type="hidden" name="url" id="url">
	</form>
	<!-- 表单 -->
</body>
</html>